package com.googlecode.allinclusive.tools.srcgen.database;


public class JavaTypeResolver {

	private String jdbcTypeName;
	
	private String fullyQualifiedName;
	
	private String baseSimpleName;
	
    private boolean explicitlyImported;
    
    private String packageName;
    
    private boolean primitive;
    
    public JavaTypeResolver(String fullyQualifiedName) {
    	this.fullyQualifiedName = fullyQualifiedName;
    	
    	 int lastIndex = fullyQualifiedName.lastIndexOf('.');
         if (lastIndex == -1) {
        	 baseSimpleName = fullyQualifiedName;
             explicitlyImported = false;
             packageName = ""; //$NON-NLS-1$
             
             if ("byte".equals(fullyQualifiedName)) { //$NON-NLS-1$
                 primitive = true;
             } else if ("short".equals(fullyQualifiedName)) { //$NON-NLS-1$
                 primitive = true;
             } else if ("int".equals(fullyQualifiedName)) { //$NON-NLS-1$
                 primitive = true;
             } else if ("long".equals(fullyQualifiedName)) { //$NON-NLS-1$
                 primitive = true;
             } else if ("char".equals(fullyQualifiedName)) { //$NON-NLS-1$
                 primitive = true;
             } else if ("float".equals(fullyQualifiedName)) { //$NON-NLS-1$
                 primitive = true;
             } else if ("double".equals(fullyQualifiedName)) { //$NON-NLS-1$
                 primitive = true;
             } else if ("boolean".equals(fullyQualifiedName)) { //$NON-NLS-1$
                 primitive = true;
             } else {
                 primitive = false;
             }
         } else {
        	 baseSimpleName = fullyQualifiedName.substring(lastIndex + 1);
             packageName = fullyQualifiedName.substring(0, lastIndex);
             if ("java.lang".equals(packageName)) { //$NON-NLS-1$
                 explicitlyImported = false;
             } else {
                 explicitlyImported = true;
             }
             primitive = false;
         }
    }

	public String getJdbcTypeName() {
		return jdbcTypeName;
	}

	public void setJdbcTypeName(String jdbcTypeName) {
		this.jdbcTypeName = jdbcTypeName;
	}

	public String getFullyQualifiedName() {
		return fullyQualifiedName;
	}

	public void setFullyQualifiedName(String fullyQualifiedName) {
		this.fullyQualifiedName = fullyQualifiedName;
	}

	public String getBaseSimpleName() {
		return baseSimpleName;
	}

	public void setBaseSimpleName(String baseSimpleName) {
		this.baseSimpleName = baseSimpleName;
	}

	public boolean isExplicitlyImported() {
		return explicitlyImported;
	}

	public void setExplicitlyImported(boolean explicitlyImported) {
		this.explicitlyImported = explicitlyImported;
	}

	public String getPackageName() {
		return packageName;
	}

	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}

	public boolean isPrimitive() {
		return primitive;
	}

	public void setPrimitive(boolean primitive) {
		this.primitive = primitive;
	}
}
